package com.example.util;


import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.apache.http.entity.StringEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class ApiHttpUtil {

    @Value("${apisix.apikey: jack}")
    private  String apikey;

    public HttpResponse httpPut(String url, String str) {
        HttpResponse httpPutResponse = HttpRequest.put(url)
                .header(Header.CONTENT_TYPE, "application/json")
                .header("X-API-KEY", apikey)
                .body(str)
                .execute();
        return httpPutResponse;
    }
    public HttpResponse httpGet(String url) {
        HttpResponse httpPutResponse = HttpRequest.get(url)
                .header(Header.CONTENT_TYPE, "application/json")
                .header("X-API-KEY", apikey)
                .execute();
        return httpPutResponse;
    }
    public HttpResponse httpPost(String url, String str) {
        HttpResponse httpPutResponse = HttpRequest.post(url)
                .header(Header.CONTENT_TYPE, "application/json")
                .header("X-API-KEY", apikey)
                .body(str)
                .execute();
        return httpPutResponse;
    }

    public  HttpResponse httpDelte(String url) {
        HttpResponse httpPutResponse = HttpRequest.delete(url)
                .header(Header.CONTENT_TYPE, "application/json")
                .header("X-API-KEY", apikey)
                .execute();
        return httpPutResponse;
    }

}
